<?php

namespace Tedivm\StashBundle\Service;

/**
 * Simple non-static wrapper for the StashBox handler. Will eventually be extended to handle things more gracefully
 * (possibly direct injection into this shell?)
 *
 * @author Josh Hall-Bachner <jhallbachner@gmail.com>
 */
class Cache
{
	/**
	 * Constructs the cache holder. Parameter is a Stash handler which is dynamically injected at service creation.
	 *
	 * @var StashHandler $handler
	 */
	public function __construct($handler)
	{
		\StashBox::setHandler($handler);
	}

	/**
	 * Returns a Stash caching object for the specified key.
	 *
	 * @param string $key, $key, $key...
	 */
	public function get()
	{
		$args = func_get_args();
		return call_user_func_array('\StashBox::getCache', $args);
	}

	/**
	 * Clears the cache (for the key, if specified.)
	 *
	 * @param null|string|array $key, $key, $key...
	 */
	public function clear()
	{
		$args = func_get_args();
		return call_user_func_array('\StashBox::clearCache', $args);
	}

	/**
	 * Purges the cache.
	 *
	 */
	public function purge()
	{
		$args = func_get_args();
		return call_user_func_array('\StashBox::purgeCache', $args);
	}

	/**
	 * Returns the current list of handlers.
	 *
	 * @return array
	 */
	public function getHandlers()
	{
		return \StashHandlers::getHandlers();
	}
}